package rateexchange.client;




import rateexchange.client.mvp.RatesActivityMapper;
import rateexchange.client.mvp.RatesPlaceHistoryMapper;
import rateexchange.client.place.RatesTablePlace;
import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;


/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */

public class RateExchange implements EntryPoint {
	//default place to start from
	private RatesTablePlace defplace = new RatesTablePlace("list");	
	private SimplePanel   container    = new SimplePanel();
		 
		
		
		public void onModuleLoad() {
			// Clientfactory interface must be instantiated via deffered binding. See also project xml contains mapping details needed for deffered binding.
			ClientFactory clientfactory = GWT.create(ClientFactory.class);
			EventBus eventBus = clientfactory.getEventBus();
			//Used to navigate between places via goTo(place)
			PlaceController placecontroller = clientfactory.getPlaceController();
			
			
			ActivityMapper mapper = new RatesActivityMapper(clientfactory);
			ActivityManager manager = new ActivityManager(mapper, eventBus);
			manager.setDisplay(container);
			
			RatesPlaceHistoryMapper historymapper = GWT.create(RatesPlaceHistoryMapper.class);
			PlaceHistoryHandler handler = new PlaceHistoryHandler(historymapper);
			handler.register(placecontroller, eventBus, defplace);
			
			//Rootpanel occupies the whole bodyelement of the homepage or an element handed over to get()
			RootPanel.get("gwt").add(container);
			handler.handleCurrentHistory();
					
	}
}
